﻿using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Demo : MonoBehaviour
{
    public Material material;
    public RawImage image;
    public Texture2D texture2D;
    private Dictionary<string, int> sdic = new Dictionary<string, int>();
    // Start is called before the first frame update
    void Start()
    {
        //Input.mousePosition;
        //Application.platform == RuntimePlatform.IPhonePlayer;
        Touch touch = Input.GetTouch(0);
        if(touch.phase==TouchPhase.Ended)
        {
        }
        transform.DOLocalMoveY(1, 1);
        var image = gameObject.GetComponent<Image>();
        //image.DOFade();
        //DG.Tweening.Core
        //var tex = gameObject.GetComponent<Text>();
        //tex.DOFade();
        //gameObject.
        //transform.childCount;
        var render = gameObject.GetComponent<Renderer>();
        var color = render.material.color;
        color.a = 0.2f;
        render.material.color = color;

        var line = gameObject.AddComponent<LineRenderer>();
        //line.sharedMaterial = 
        line.positionCount = 2;
        line.startWidth = 5;
        line.endWidth = 5;
        line.startColor = new Color();
        line.endColor = new Color();
        line.SetPosition(0, new Vector3(0, 0, 0));

        var rect = gameObject.GetComponent<RectTransform>();
        var count = rect.childCount;
        rect.GetChild(0);
        rect.sizeDelta = new Vector2(300, 26);
        rect.anchoredPosition = new Vector2(0, 0.5f);
        rect.anchorMax = new Vector2(0, 0.5f);
        rect.anchorMin = new Vector2(0, 0.5f);

        //RectTransform;
        var text = gameObject.GetComponent<Text>();
        text.fontSize = 20;
        //text.preferredWidth = 20;
        //text.preferredHeight = 20;
        var inutvar = gameObject.GetComponent<InputField>();
        inutvar.text = "";
        var box = gameObject.AddComponent<BoxCollider>();
        box.size = new Vector3(1, 1, 3);
        box.center = new Vector3(0, 1, 1.5f);
        //var rect = gameObject.GetComponent<RectTransform>();
        //0,1,1.5，
        //    1,1,3
        //rect.anchoredPosition;
        //text.preferredHeight;
        //rect.sizeDelta= Vector2.new()
        //text.preferredWidth;
        //text.rectTransform.sizeDelta
        //Outline
        //Debug.Log("Demo start");
        //sdic.Add("hahah", 22);
        //sdic.Remove("cccc");
        //foreach (var key in sdic.Keys)
        //{
        //    Debug.Log(sdic[key]);
        //}
        //var line = gameObject.AddComponent<LineRenderer>();
        //line.material = material;
        //Vector3[] poss = new Vector3[2] { new Vector3(0, 0, 0), new Vector3(0, 10, 0) };
        //line.SetPositions(poss);


        //transform.RotateAround(,,)
        //Animator animator;
        //transform.eulerAngles
        //transform.LookAt(new Vector3());
        //Application.persistentDataPath;
        //var text = gameObject.GetComponent<Text>();
        //var entry = new UnityEngine.EventSystems.EventTrigger.Entry();
        //entry.eventID = UnityEngine.EventSystems.EventTriggerType.PointerClick;
        //Image image = gameObject.GetComponent<Image>();
        //image.SetNativeSize();
        //transform.LookAt(new Vector3());
        //animator.IsInTransition(0);
        //transform.LookAt()
        //Physics.RaycastAll
        //CharacterController character;
        //character.
        //LineRenderer lineRenderer = new LineRenderer();
        //lineRenderer.transform.position
        //transform.Translate()
        //CharacterController controller;
        //KeyCode keyCode;
        //Application.platform=
        //int layer = LayerMask.GetMask("layer");
        //Debug.Log
        //RectTransform re;
        //re.localEulerAngles
        ////Vector2 vec
        //     = new Vector2();
        //RectTransformUtility.WorldToScreenPoint(Camera.main, new Vector3(0, 0, 0));
        //RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, new Vector3(), Camera.main, outPos);
        //transform.RotateAround(new Vector3(), Vector3.up, 10);
        //Camera camera = new Camera();
        //string[] layers = { "Default", "UI" };
        //camera.cullingMask = LayerMask.GetMask(layers);
        //transform.DOMove(new Vector3(0, 0, 0), 1);
        //transform.DORotate(new Vector3(0, 0, 0), 1);
        //transform.DORotate(new Vector3());
        //transform.Find("name");
        //GameObject.Find("name");
        //transform.GetChild(0);
        //transform.SetSiblingIndex()
        //var color = new Color(1, 1, 1, 1);
        //gameObject.transform.localPosition = new Vector3(100, 0, 0);
        //var cameraObj = new GameObject();
        //var camera = cameraObj.AddComponent<Camera>();
        //camera.clearFlags = CameraClearFlags.SolidColor;
        //cameraObj.transform.SetParent(gameObject.transform);
        //cameraObj.transform.localPosition = new Vector3(0, 0.41f, 1.2f);
        //cameraObj.transform.eulerAngles = new Vector3(0, 180, 0);
        //camera.targetTexture = new RenderTexture(256, 256, 4);
        //camera.cullingMask = LayerMask.GetMask("ShowModel");
        //image.texture = camera.targetTexture;
        //cameraObj.layer = LayerMask.GetMask("ShowModel");
        //camera.orthographic = true;

        //var rotate = transform.DOLocalRotate(new Vector3(0, 0, 180), 1);
        //var sequne = DOTween.Sequence();
        //sequne.Append(rotate);
        //sequne.AppendInterval(0.5f);
        //sequne.SetLoops(-1);

        //RectTransform rect = gameObject.GetComponent<RectTransform>();
        //rect.DOLo
     
        //transform.SetSiblingIndex(999);
  

        //gameObject.SetActive()
        //transform.GetChild(0);

        //Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f));
        //RaycastHit raycastHit;
        //Physics.Raycast(ray, out raycastHit);
        //transform.DOMove(new Vector3(), 1);
        //RectTransform rect = gameObject.GetComponent<RectTransform>();
        //rect.sizeDelta = new Vector2(0, 0);
        //Animator animator = GetComponent<Animator>();
        //animator.SetTrigger("as");
        //Instantiate(new GameObject("Story"));
        //print(GameObject.Find("UICamera"));
        //material = GetComponent<Renderer>().material;
        //GameObject juqing = Resources.Load<GameObject>("Prefabs/Story/juqing1");
        //SearchChild(juqing.transform);
        //material.SetTexture("_MainTex", tex);
        //transform.position./*normalized*/;
        //var pos = transform.localToWorldMatrix.MultiplyPoint(new Vector3(1, 0, 0));
        //print(pos);
        //transform./*localEulerAngles*/
        //transform.DOLookAt();
        //transform.DOLocalRotate()
        //transform.Find("root");
        //transform.LookAt(new Vector3());

        //RectTransform rect;
        //rect.sizeDelta=
        //Canvas canvas;
        //canvas.scaleFactor
        //gameObject.layer = LayerMask.NameToLayer("ShowModel");
        //Image image;
        //image.raycastTarget = false;
        //image.SetNativeSize();
        //var light= gameObject.AddComponent<Light>();
        //light.type = LightType.Point;
        //light.intensity = 2;
        //var entryEndDrag = new UnityEngine.EventSystems.EventTrigger.Entry();
        //entryEndDrag.eventID = UnityEngine.EventSystems.EventTriggerType.PointerUp;
        //entryEndDrag.callback.AddListener((UnityEngine.EventSystems.BaseEventData eventData) => {
        //    var eventData1 = (UnityEngine.EventSystems.PointerEventData)(eventData);
        //    var pos = eventData1.position;
        //    eventData1.delta;
        //});
        //transform.GetChild(0);
        //RectTransformUtility.()
        //var controller = gameObject.AddComponent<CharacterController>();
        //var sphere = gameObject.AddComponent<SphereCollider>();
        //sphere.isTrigger = true;
        //sphere.radius = 10;
        //Physics.Raycast(new Ray(new Vector3(), new Vector3()), 10);

        //RaycastHit raycastHit;
        //Ray ray;
        //if(Physics.Raycast(transform.position, transform.forward,out raycastHit, 2, LayerMask.GetMask("Default")))
        //{
        //    if(!raycastHit.collider.CompareTag("Player"))
        //    {
        //        return;
        //    }    
        //}    
        //var canvas = gameObject.GetComponent<Canvas>();
        //canvas.renderMode = RenderMode.WorldSpace;
        //canvas.worldCamera = 
        //Input.mousePosition;
    }

    void Awake()
    {
        Debug.Log("Demo Awake");
    }

    void OnEnable()
    {
        Debug.Log("Demo enable");
    }

    void OnDisable()
    {
        Debug.Log("Demo disable");
    }

    void OnDestroy()
    {
        Debug.Log("Demo destory");
    }

    void SearchChild(Transform trans)
    {
        for (int i = 0; i < trans.childCount; ++i)
        {
            print(trans.GetChild(i));
            SearchChild(trans.GetChild(i));
        }
    }

    void onTriggerEnter(Collider other)
    {
    }

    private void OnCollisionEnter(Collision collision)
    {
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    IEnumerator corTest()
    {
        yield return new WaitForSeconds(0.5f);
    }
}
